package com.bamboo.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* @description 
* @date 2025/3/27 下午2:42
* @author chenzh
*/
public enum FileTypeEnum {
    DOC("doc", "文档"),
    VIDEO("video", "视频"),
    AUDIO("audio", "音频"),
    IMAGE("image", "图片"),
    OTHER("other", "其他"),
    ;

    private static final List<String> docSuffix = Arrays.asList(
            "doc", "docx", "pdf", "txt", "md", "markdown", "ppt", "pptx",
            "xls", "xlsx", "csv", "rtf"
    );
    private static final List<String> videoSuffix = Arrays.asList(
            "mp4", "avi", "mov", "wmv", "flv", "mkv", "mpeg", "mpg", "webm", "3gp", "m4v"
    );
    private static final List<String> audioSuffix = Arrays.asList(
            "mp3", "wav", "aac", "flac", "ogg"
    );
    private static final List<String> picSuffix = Arrays.asList(
            "jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "ico", "psd"
    );
    @EnumValue
    private final String code;
    private final String name;
    FileTypeEnum(final String code, final String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    /**
     * @description 根据文件后缀名返回所属的文件类型
     * @date 2025/4/3 上午10:43
     * @author chenzh
     * @param suffix 文件后缀名
     * @return FileTypeEnum
     */
    public static FileTypeEnum getEnumBySuffix(String suffix) {
        if (docSuffix.contains(suffix)) {
            return DOC;
        }
        if (videoSuffix.contains(suffix)) {
            return VIDEO;
        }
        if (audioSuffix.contains(suffix)) {
            return AUDIO;
        }
        if (picSuffix.contains(suffix)) {
            return IMAGE;
        }
        return OTHER;
    }

    /**
     * @description 获取所有支持的文件类型
     * @date 2025/4/3 上午10:44
     * @author chenzh
     * @return List<String>
     */
    public static List<String> getAllTypes() {
        List<String> typeList = new ArrayList<>();
        typeList.addAll(docSuffix);
        typeList.addAll(videoSuffix);
        typeList.addAll(audioSuffix);
        typeList.addAll(picSuffix);
        return typeList;
    }
}
